﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Pumptester.ExperimentForms.Base
{
    public partial class ValueEditForm : Form
    {
        private String returnValue;

        public ValueEditForm(String lableText,String sourceValue)
        {
            InitializeComponent();
            this.textBoxValue.Text = sourceValue;
            this.Text = lableText;
            
        }

        public string ReturnValue { get => returnValue; set => returnValue = value; }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            ReturnValue = this.textBoxValue.Text;
            this.DialogResult = DialogResult.OK;
            this.Close();
            
        }

        private void ValueEditForm_Load(object sender, EventArgs e)
        {
            this.textBoxValue.Focus();
            
        }

        private void textBoxValue_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter&&this.textBoxValue.Text.Trim().Length!=0)
            {
                ReturnValue = this.textBoxValue.Text;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else if (e.KeyCode == Keys.Escape)
            {
                this.DialogResult = DialogResult.Cancel;
                this.Close();
            }
        }


    }
}
